package com.beiding.jsonanalyzer.flow;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 丁常磊
 * @date 2022/5/13 15:33
 */

public class BranchFactory {


    public static <T> Branch<T> createSelfExecuteBranch(Object referKey, Object refer, ValueNodeFactory<T> valueNodeFactory) {
        Branch<T> branch = new Branch<>();
        branch.setReferKeyValue(referKey,refer);
        List<Object> rfs = new ArrayList<>();
        rfs.add(refer);
        branch.setBranchReferLink(rfs);

        branch.setValueNodeFactory(valueNodeFactory);
        branch.setTaskSlot(SelfExecuteTaskSlot.getInstance());
        branch.setComputeResource(new SelfExecuteComputeResource());

        BranchNode<T> branchNode = new BranchNode<>(branch);

        branch.setFirstNode(branchNode);

        branch.setChildren(new ArrayList<>());

        branch.setName("[" + branch.getReferKey() + "=" + refer + "]");


        return branch;
    }
}
